
/**
 * Team Site Connection Constructor
 * @class Provides methods to interact with an existing Team Site.
 * @param {String} URL The web address that points to the designated Team Site.
 * @property {String} URL The web address that points to the designated Team Site.
 * @property {Workspace[]} Workspaces The collection of workspaces that are directly owned by this Team Site.
 * @requires SharePoint
 */
function TeamSite (URL, ForceCreate) {
	
	var self = this;
	
	this.URL = URL;
	
	/**
	 * Update the Team Site with values from the server.
	 * @returns Boolean True on success, false upon failure.
	 */
	this.Refresh = function () {
		
		var success = true;
		
		// Fetch meta information
		$().SPServices ({
			operation: "GetWeb",
			webURL: self.URL,
			async: false,
			completefunc: function (result, status) {
				if (status == "success") {
					var properties = $(result).find ("Web");
					self.Title = properties.attr ("Title");
					self.Description = properties.attr ("Description");
					self.Language = properties.attr ("Language");
					self.Theme = properties.attr ("Theme");
				} else {
					if (ForceCreate) {
						self.Push ();
					} else {
						success = false;
					}
				}
			}
		});
		
		// Fetch the workspaces
		self.Workspaces = [];
		$().SPServices({
			operation: "GetAllSubWebCollection",
			webURL: self.URL,
			async: false,
			completefunc: function (result, status) {
				if (status == "success") {
					$(result.responseXML).find ("Webs > Web").each (function () {
						var web = $(this);
						var NewWorkspace = new Workspace (web.attr('url'));
						self.Workspaces[NewWorkspace.URL] = NewWorkspace;
					});
				} else {
					success = false;
				}
			}
		});
		
		return success;
	}
	
	/**
	 * Push changes to the Team Site to the web.
	 */
	this.Push = function () {
		
	}
	
	// Initialize the Team Site
	this.Refresh ();
}
